home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / The World of Computer Software.iso / drcpas10.zip / ROOTDIR.PAS < prev    next >
Pascal/Delphi Source File  |  1992-11-17  |  5KB  |  171 lines

  1. {$A+,B-,D-,E-,F-,I+,L-,N-,O-,R-,S+,V-}
  2. {$M 16384,0,655360}
  3. program rootdir;
  4.  
  5. (* another absio.pas example: display the root directory of the current
  6.    disk without (much) help from DOS; also compute locations of FAT's,
  7.    root dir and data from information in boot sector.
  8. *)
  9.  
  10. uses dos, absio, tools;
  11.  
  12. (*
  13. Note: DOS directories have the following structure:
  14.  
  15.    Filename   = 8 bytes
  16.    Extention  = 3 bytes
  17.    Attribute  = 1 byte
  18.    Unused     = 10 bytes
  19.    Time       = 2 bytes
  20.    Date       = 2 bytes
  21.    Cluster    = 2 bytes
  22.    File Size  = 4 bytes
  23. *)
  24.  
  25. type
  26.   dirent =
  27.     record
  28.       filename  : array[1..8] of char;
  29.       extention : array[1..3] of char;
  30.       attribute : byte;
  31.       unused    : array[1..10] of byte;
  32.       time      : word;
  33.       date      : word;
  34.       cluster   : word;
  35.       size      : longint;
  36.     end;
  37.   sector = array[0..511] of byte;
  38.   dirsect = array[1..16] of dirent;
  39.  
  40. procedure abort (message : string);
  41. begin
  42.   writeln ('Error: ', message);
  43.   halt (2);
  44. end;
  45.  
  46. function getdisk : byte;
  47. var
  48.   reg : registers;
  49. begin
  50.   reg.ah := $19;
  51.   intr ($21, reg);
  52.   getdisk := reg.al;
  53. end;
  54.  
  55. procedure printent (e : dirent);
  56. begin
  57.   if e.filename[1] = #$e5 then
  58.     begin
  59.       e.filename[1] := '.';
  60.       write (e.filename, '.', e.extention, e.cluster:8);
  61.       writeln ('   (deleted)');
  62.     end
  63.   else
  64.     if (e.attribute AND VolumeID) = VolumeID then
  65.       writeln (chr(65+getdisk), ': "', e.filename, e.extention, '":')
  66.     else
  67.       begin
  68.         write (e.filename, '.', e.extention, e.cluster:8);
  69.         if (e.attribute AND Directory) = Directory then
  70.           write ('   DIR') else write ('      ');
  71.         if (e.attribute AND Sysfile) = Sysfile then
  72.           write ('   SYS') else write ('      ');
  73.         if (e.attribute AND Hidden) = Hidden then
  74.           write ('   HID') else write ('      ');
  75.         if (e.attribute AND Archive) = Archive then
  76.           write ('   ARC') else write ('      ');
  77.         if (e.attribute AND ReadOnly) = ReadOnly then
  78.           write ('   RO') else write ('     ');
  79.         writeln;
  80.       end;
  81. end;
  82.  
  83. var
  84.   bootsec : sector;
  85.   s : dirsect;
  86.   bps, skip, ent, spf, spt, tpc, hid, ot : word;
  87.   spc, fats, media, id, sig : byte;
  88.   nt, tot : longint;
  89.  
  90. (*
  91.  
  92. Offset  Format and example   Contents
  93.  
  94.   0     jmp around           either a 3-byte jmp or 2-byte jmp plus NOP.
  95.   3     db  'MSDOS5.0'       OEM name
  96.   B     dw  512              bytes/sector
  97.   D     db  4                sectors/cluster
  98.   E     dw  1                reserved sectors at front of disk
  99.  10     db  2                number of copies of the FAT
  100.  11     dw  512              number of root directory entries
  101.  13     dw  0                *old* total number of sectors
  102.  15     db  0F8h             media descriptor
  103.  16     dw  64               sectors/FAT
  104.  18     dw  32               sectors/track
  105.  1A     dw  64               tracks/cylinder
  106.  1C     dd  32               "hidden" sectors
  107.  20     dd  65504            *new* total number of sectors
  108.  24     db  080h             physical disk ID
  109.  25     db  0                reserved (used as scratch during boot)
  110.  26     db  029h             extended boot record signature
  111.  27     db  1ch,9eh,0adh,16h volume serial
  112.  2B     db  '           '    volume *label* if this is a diskette
  113.  36     db  'FAT16   '       ASCII text describing type of FAT
  114.  
  115. *)
  116.  
  117. var
  118.   fat, d : byte;
  119.   dat, sect : word;
  120.  
  121. begin
  122.   absread (getdisk, 0, 1, bootsec);
  123.   if abserror <> 0 then
  124.     begin
  125.       writeln ('Error ',hexw(abserror),' reading boot sector.');
  126.       halt (1);
  127.     end;
  128.   bps := word((@bootsec[$b])^);
  129.   spc := byte((@bootsec[$d])^);
  130.   skip := word((@bootsec[$e])^);
  131.   fats := byte((@bootsec[$10])^);
  132.   ent := word((@bootsec[$11])^);
  133.   ot := word((@bootsec[$13])^);
  134.   media := byte((@bootsec[$15])^);
  135.   spf := word((@bootsec[$16])^);
  136.   spt := word((@bootsec[$18])^);
  137.   tpc := word((@bootsec[$1a])^);
  138.   hid := word((@bootsec[$1c])^);
  139.   nt := longint((@bootsec[$20])^);
  140.   writeln ('Information for drive ', chr(65+getdisk), ':');
  141.   writeln ('Bytes per Sector: ':30, bps:5);
  142.   writeln ('Sectors per Cluster: ':30, spc:5);
  143.   writeln ('Reserved Sectors: ':30, skip:5);
  144.   writeln ('File Allocation Tables: ':30, fats:5);
  145.   writeln ('Root Directory Entries: ':30, ent:5);
  146.   writeln ('Sectors per FAT: ':30, spf:5);
  147.   tot := ot + nt;
  148.   writeln ('Total Number of Sectors: ':30, tot:5);
  149.   writeln;
  150.   writeln ('Boot Sector: ':20, 0:4);
  151.   for fat := 1 to fats do
  152.     writeln ('FAT ':17, fat, ': ', skip+(fat-1)*spf:2, ' - ', skip+fat*spf-1);
  153.   dat := skip+fats*spf+ent*32 DIV bps;
  154.   writeln ('Root Directory: ':20, skip+fats*spf:2, ' - ', dat-1);
  155.   writeln ('Data: ':20, skip+fats*spf+ent*32 DIV bps:2, ' - ', ((tot-(dat-1)) DIV spc)*spc+dat-1);
  156.  
  157.   writeln;
  158.   for sect := skip+fats*spf to dat-1 do
  159.     begin
  160.       absread (getdisk, sect, 1, s);
  161.       if abserror <> 0 then
  162.         begin
  163.           writeln ('Error ',hexw(abserror),' reading sector ',sect,'.');
  164.           halt (1);
  165.         end;
  166.       for d := 1 to bps DIV 32 do
  167.         if (s[d].filename[1] <> #0) then
  168.           printent(s[d]);
  169.     end;
  170. end.
  171.